import type { Profile } from '@/types/user'
import { getLocalToken, removeLocalToken, setLocalToken } from '@/utils/auth'
import { defineStore } from 'pinia'
import { ref } from 'vue'

export const useUserStore = defineStore('hm-user', () => {
  const token = ref(getLocalToken() || '')
  // 个人信息
  const profile = ref<Profile>({} as Profile)
  const setProfile = (p: Profile) => {
      profile.value = p
  }
  // 获取token
  const setToken = (val: string)=>{
    token.value = val
    // 持久化
    setLocalToken(val)
  }
  // 清除token
  const clearToken = ()=>{
    token.value = ''
    // 清除
    removeLocalToken()
  }
  return {token, setToken, clearToken,profile,setProfile}
})
